package cn.edu.scau.cmi.youbaiquan.controller;

import javafx.fxml.FXML;

import com.sun.scenario.effect.Effect.AccelType;

import cn.edu.scau.cmi.youbaiquan.singleton.Chairman;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;

import javafx.scene.control.TextField;
import javafx.scene.control.Alert.AlertType;

public class SingletonSceneController {
	@FXML
	private Button create_one;
	@FXML
	private Button get_object;
	@FXML
	private TextField object1;
	@FXML
	private TextField address1;
	@FXML
	private TextField object_name1;
	@FXML
	private TextField object_address1;
	@FXML
	private TextField address2;
	@FXML
	private TextField object2;
	@FXML
	private Button create_two;
	@FXML
	private TextField object_name2;
	@FXML
	private TextField object_address2;

	@FXML
	private void createChairman1() {
		if(object1.getText().length() < 1) {
			Alert alert = new Alert(AlertType.ERROR);
			alert.setTitle("Error Dialog");
			alert.setHeaderText("请输入对象名");
			alert.showAndWait();
			return;
		}
		Chairman chairman1 = Chairman.getInstance(object1.getText());
		address1.setText(chairman1.toString());
	}
	
	@FXML
	private void createChairman2() {
		if(object2.getText().length() < 1) {
			Alert alert = new Alert(AlertType.ERROR);
			alert.setTitle("Error Dialog");
			alert.setHeaderText("请输入对象名");
			alert.showAndWait();
			return;
		}
		Chairman chairman2 = Chairman.getInstance(object2.getText());
		address2.setText(chairman2.toString());
	}
	
	@FXML
	private void getChairman1() {
		object_name1.setText(Chairman.getInstance(object1.getText()).getName());
		object_address1.setText(Chairman.getInstance(object1.getText()).toString());
	}
	
	@FXML
	private void getChairman2() {
		object_name2.setText(Chairman.getInstance(object2.getText()).getName());
		object_address2.setText(Chairman.getInstance(object2.getText()).toString());
	}

}
